package com.wy2cloud.jjwt;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;



@Configuration
@ConditionalOnClass(JsonWebTokenUtil.class)
@EnableConfigurationProperties(JsonWebTokenProperties.class)
public class JsonWebTokenAutoConfiguration {

	@Autowired
    private JsonWebTokenProperties properties;

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "wy2cloud.jjwt",value = "enabled",havingValue = "true")
    JsonWebTokenUtil jsonWebTokenUtil (){
        return  new JsonWebTokenUtil(properties.getSecret(),properties.getExpiration(),
        		properties.getRequestParam(),
        		properties.getCookieName(),properties.getTokenHeader(),properties.getTokenHead(),
        		properties.getTokenStores());
    }
}
